from typing import List


class Solution:
    def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int:
        new_list = []
        for i in range(len(gas)):
            new_list.append(gas[i] - cost[i])
        length = len(cost)
        for i in range(len(gas)):
            start = i
            cap = gas[i]
            count = 0
            while cap >= cost[i]:
                print(cap, i)
                if i + 1 < length:
                    cap = cap - cost[i] + gas[i + 1]
                    i += 1

                else:
                    cap = cap - cost[i] + gas[0]
                    i = 0
                count += 1
                if count == length + 1:
                    return start

        return -1


if __name__ == "__main__":
    gas = [1, 2, 3, 4, 5]
    cost = [3, 4, 5, 1, 2]
    res = Solution().canCompleteCircuit(gas, cost)
    print(res)
